package org.adl.registry.types;

import java.util.ArrayList;

/**
 *
 * @author Jacob Marks - Joint ADL Co-Lab
 * @version 1.0
 * @license This software is licensed as open source software pursuant to the terms defined in the Joint ADL Co-Lab Open Source Software License.  Use of any part of this software constitutes acceptance of this license. The Joint ADL Co-Lab open source agreement is available at {@link http://adlregistry.adlnet.gov/source_license.html}.
 */
public class Registry extends RimParameter
{
    public static final String OPERATIONAL_REGISTRY_HANDLE = "100.3/registry";
    public static final String PRACTICE_REGISTRY_HANDLE = "4444/registry";
    
    public static final String OPERATIONAL_REGISTRY_NAMESPACE = "100.3";
    public static final String PRACTICE_REGISTRY_NAMESPACE = "4444";
    
    public static final String REGISTRY_HANDLE_SUFFIX = "registry";

    public Registry(String iValue)
    {
        super("registry", iValue);
        
        this.validate();
    }
    
    protected void validate()
    {
        String value = super.getParameterValue();
        
        String[] parts = value.split("/");
        
        if (parts.length != 2)
        {
            super.getValidaionErrors().add("The provided registry value does not conform to standard registry handle syntax.");
        }
        else
        {
            String prefix = (String)parts[0];
            
            if ((prefix.equalsIgnoreCase(Registry.OPERATIONAL_REGISTRY_NAMESPACE) == false) && (prefix.equalsIgnoreCase(Registry.PRACTICE_REGISTRY_NAMESPACE) == false))
            {
                super.getValidaionErrors().add("The provided registry value does not begin with a valid registry type prefix.");
            }
            
            String suffix = (String)parts[1];
            
            if(suffix.equalsIgnoreCase(Registry.REGISTRY_HANDLE_SUFFIX) == false)
            {
                super.getValidaionErrors().add("The provided registry value does not contain a valid suffix.");
            }
        }
    }
}
